package com.nulldev.util.networking.npacket4.iprotocols.ncryptx;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import com.nulldev.util.networking.npacket4.nPacket;
import com.nulldev.util.networking.npacket4.extensions.PacketExtension;
import com.nulldev.util.security.encryptAPI.Encryptors.SystemEncryptors;

public class nCryptSelectedCipherInformation extends nPacket {

	private static final long serialVersionUID = 4675262677953062921L;
	private SystemEncryptors cipher;
	private byte cryptVersion = nCryptX.CRYPT_VERSION;

	public nCryptSelectedCipherInformation(final nPacket packet) {
		super("ncryptx.selected_cipher_info", packet);
	}

	public nCryptSelectedCipherInformation(final SystemEncryptors cipher, final PacketExtension... exts) {
		super("ncryptx.selected_cipher_info", exts);
		this.cipher = cipher;
	}

	@Override
	public void onGenerate(final DataOutputStream dos) throws IOException {
		dos.writeByte(this.cryptVersion);
		dos.writeInt(this.cipher.cipherID());
	}

	@Override
	public void onPacket(final DataInputStream dis) throws IOException {
		this.cryptVersion = dis.readByte();
		this.cipher = SystemEncryptors.get(dis.readInt());
	}

	public SystemEncryptors getCipher() {
		return this.cipher;
	}

	public byte getCryptVersion() {
		return this.cryptVersion;
	}

}
